import {
  Controller,
  Post,
  DefaultValuePipe,
  ParseIntPipe,
  Param,
  Body,
} from '@nestjs/common';
import { LogService } from './log.service';
import { GetUser } from '../auth/get-user.decorator';
import { User } from '../user/entities/user.entity';
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { CreateLogDto } from './dto/create-log.dto';
import { Pagination } from '../utils/paginate';
import { Log } from './entities/log.entity';
@Controller('log')
@ApiTags('log')
export class LogController {
  constructor(private readonly logService: LogService) {}
  @ApiOperation({
    summary: '创建日志',
  })
  @Post('/addLog')
  create(
    @Body() createLogDto: CreateLogDto,
    @GetUser() user: User,
  ): Promise<string> {
    return this.logService.create(createLogDto, user);
  }
  @ApiOperation({
    summary: '获取日志',
  })
  // @ApiParam({
  //   name: 'pageNum',
  //   required: false,
  // })
  // @ApiParam({
  //   name: 'pageSize',
  //   required: false,
  // })
  @Post('/getLogList')
  findAll(
    @Param('pageNum', new DefaultValuePipe(0), ParseIntPipe) pageNum: number,
    @Param('pageSize', new DefaultValuePipe(0), ParseIntPipe) pageSize: number,
  ): Promise<Pagination<Log>> {
    pageSize = pageSize > 100 ? 100 : pageSize;
    return this.logService.findAll({
      page: pageNum,
      limit: pageSize,
    });
  }
}
